package edu.rjxy.xjdx.emps.service;

import edu.rjxy.xjdx.emps.common.domain.User;
import edu.rjxy.xjdx.emps.dao.UserDao;
import edu.rjxy.xjdx.emps.dao.UserDaoImpl;

public class UserServiceImpl implements UserService {
    //服务层 注入 Dao层
    UserDao userDao =  new UserDaoImpl();
    //1 OK  -1 用户名不存在   0 密码错误
    public int login(String loginName, String password) {
        User userInDB = userDao.selectUserByLoginName(loginName);
        /*if(userInDB==null){
            return -1;//
        }else {
            if(userInDB.getPassword().equals(password)){
                return 1;
            }else {
                return 0;
            }
        }*/
        return (userInDB==null?-1:(userInDB.getPassword().equals(password)?1:0));
    }

    @Override
    public User findUserByLoginname(String loginName) {
        return userDao.selectUserByLoginName(loginName);
    }

    @Override
    public void updatePasswordByLoginname(String newpassword, String loginName) {
         userDao.updatePasswordByLoginname(newpassword,loginName);
    }


}
